home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / ghostview / main.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  48KB  |  1,177 lines

  1. /*
  2.  * main.c -- Main routine for ghostview.
  3.  * Copyright (C) 1992  Timothy O. Theisen
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *   Author: Tim Theisen           Systems Programmer
  20.  * Internet: tim@cs.wisc.edu       Department of Computer Sciences
  21.  *     UUCP: uwvax!tim             University of Wisconsin-Madison
  22.  *    Phone: (608)262-0438         1210 West Dayton Street
  23.  *      FAX: (608)262-9777         Madison, WI   53706
  24.  */
  25.  
  26. #include <X11/Intrinsic.h>
  27. #include <X11/cursorfont.h>
  28. #include <X11/StringDefs.h>
  29. #include <X11/Shell.h>
  30. #ifdef VMS
  31. #include <X11/bitmaps/dot.>
  32. #include <X11/bitmaps/menu16.>
  33. #include <X11/bitmaps/tie_fighter.>
  34. #else
  35. #include <X11/bitmaps/dot>
  36. #include <X11/bitmaps/menu16>
  37. #include <X11/bitmaps/tie_fighter>
  38. #endif
  39.  
  40. #include <X11/Xaw/Cardinals.h>
  41. #include <X11/Xaw/Form.h>
  42. #include <X11/Xaw/Viewport.h>
  43. #include <X11/Xaw/Box.h>
  44. #include <X11/Xaw/MenuButton.h>
  45. #include <X11/Xaw/SimpleMenu.h>
  46. #include <X11/Xaw/SmeBSB.h>
  47. #include <X11/Xaw/SmeLine.h>
  48. #include <X11/Xaw/Label.h>
  49. #include <X11/Xaw/AsciiText.h>
  50. #include <X11/Xaw/Command.h>
  51.  
  52. #include "Ghostview.h"
  53. #include "gv.h"
  54. #include "ps.h"
  55.  
  56. extern char *getenv();
  57.  
  58. static String version = "Ghostview, version 1.4.1";
  59.  
  60. static XtResource resources[] = {
  61.     {"showTitle", "Labels", XtRBoolean, sizeof(Boolean),
  62.      XtOffsetOf(AppResources, show_title), XtRImmediate, (XtPointer)True},
  63.     {"showDate", "Labels", XtRBoolean, sizeof(Boolean),
  64.      XtOffsetOf(AppResources, show_date), XtRImmediate, (XtPointer)True},
  65.     {"showLocator", "Labels", XtRBoolean, sizeof(Boolean),
  66.      XtOffsetOf(AppResources, show_locator), XtRImmediate, (XtPointer)True},
  67.     {"installStdCmap", "InstallStdCmap", XtRBoolean, sizeof(Boolean),
  68.      XtOffsetOf(AppResources, install_std_cmap), XtRImmediate,
  69.      (XtPointer)False},
  70.     {"retainStdCmap", "RetainStdCmap", XtRBoolean, sizeof(Boolean),
  71.      XtOffsetOf(AppResources, retain_std_cmap), XtRImmediate, (XtPointer)True},
  72.     {"privateCmap", "PrivateCmap", XtRBoolean, sizeof(Boolean),
  73.      XtOffsetOf(AppResources, private_cmap), XtRImmediate, (XtPointer)False},
  74.     {"autoCenter", "AutoCenter", XtRBoolean, sizeof(Boolean),
  75.      XtOffsetOf(AppResources, auto_center), XtRImmediate, (XtPointer)True},
  76.     {"horizontalMargin", "Margin", XtRInt, sizeof(int),
  77.      XtOffsetOf(AppResources, wm_horiz_margin), XtRImmediate, (XtPointer)20},
  78.     {"verticalMargin", "Margin", XtRInt, sizeof(int),
  79.      XtOffsetOf(AppResources, wm_vert_margin), XtRImmediate, (XtPointer)44},
  80.     {"minimumMagstep", "Magstep", XtRInt, sizeof(int),
  81.      XtOffsetOf(AppResources, minimum_magstep), XtRImmediate, (XtPointer)-5},
  82.     {"maximumMagstep", "Magstep", XtRInt, sizeof(int),
  83.      XtOffsetOf(AppResources, maximum_magstep), XtRImmediate, (XtPointer)5},
  84.     {"magstep", "Magstep", XtRInt, sizeof(int),
  85.      XtOffsetOf(AppResources, magstep), XtRImmediate, (XtPointer)0},
  86.     {"orientation", "Orientation", XtRPageOrientation,
  87.      sizeof(XtPageOrientation), XtOffsetOf(AppResources, orientation),
  88.      XtRImmediate, (XtPointer) XtPageOrientationPortrait},
  89.     {"page", "Page", XtRString, sizeof(String),
  90.      XtOffsetOf(AppResources, page), XtRImmediate, NULL},
  91.     {"pageMedia", "PageMedia", XtRString, sizeof(String),
  92.      XtOffsetOf(AppResources, pagemedia), XtRImmediate, "Letter"},
  93.     {"forceOrientation", "Force", XtRBoolean, sizeof(Boolean),
  94.      XtOffsetOf(AppResources, force_orientation), XtRImmediate,
  95.      (XtPointer)False},
  96.     {"forcePageMedia", "Force", XtRBoolean, sizeof(Boolean),
  97.      XtOffsetOf(AppResources, force_pagemedia), XtRImmediate, (XtPointer)False},
  98.     {"swapLandscape", "SwapLandscape", XtRBoolean, sizeof(Boolean),
  99.      XtOffsetOf(AppResources, swap_landscape), XtRImmediate, (XtPointer)False},
  100. #ifndef VMS
  101. #if defined(SVR4) || defined(SYSV) || defined(USG)
  102.     {"printCommand", "PrintCommand", XtRString, sizeof(String),
  103.      XtOffsetOf(AppResources, print_command), XtRImmediate, "lp"},
  104.     {"printerVariable", "PrinterVariable", XtRString, sizeof(String),
  105.      XtOffsetOf(AppResources, printer_variable), XtRImmediate, "LPDEST"},
  106. #else
  107.     {"printCommand", "PrintCommand", XtRString, sizeof(String),
  108.      XtOffsetOf(AppResources, print_command), XtRImmediate, "lpr"},
  109.     {"printerVariable", "PrinterVariable", XtRString, sizeof(String),
  110.      XtOffsetOf(AppResources, printer_variable), XtRImmediate, "PRINTER"},
  111. #endif
  112.     {"printPrompt", "PrintPrompt", XtRString, sizeof(String),
  113.      XtOffsetOf(AppResources, print_prompt), XtRImmediate, "Printer Name:"},
  114. #else /* VMS */
  115.     {"printCommand", "PrintCommand", XtRString, sizeof(String),
  116.      XtOffsetOf(AppResources, print_command), XtRImmediate, "Print_dcl/Delete"},
  117.     {"printerVariable", "PrinterVariable", XtRString, sizeof(String),
  118.      XtOffsetOf(AppResources, printer_variable), XtRImmediate, "GV_PRINT_QUAL"},
  119.     {"printPrompt", "PrintPrompt", XtRString, sizeof(String),
  120.      XtOffsetOf(AppResources, print_prompt), XtRImmediate, "Print Qualifiers:"},
  121. #endif /* VMS */
  122.     {"defaultPrinter", "DefaultPrinter", XtRString, sizeof(String),
  123.      XtOffsetOf(AppResources, default_printer), XtRImmediate, NULL},
  124.     {"printFail", "printFail", XtRString, sizeof(String),
  125.      XtOffsetOf(AppResources, print_fail), XtRImmediate,
  126.      "\"%s\" command failed."},
  127.     {"openPrompt", "OpenPrompt", XtRString, sizeof(String),
  128.      XtOffsetOf(AppResources, open_prompt), XtRImmediate, "Open File:"},
  129.     {"openFail", "OpenFail", XtRString, sizeof(String),
  130.      XtOffsetOf(AppResources, open_fail), XtRImmediate, "Cannot open file: "},
  131.     {"savePrompt", "SavePrompt", XtRString, sizeof(String),
  132.      XtOffsetOf(AppResources, save_prompt), XtRImmediate, "Save File:"},
  133.     {"saveFail", "SaveFail", XtRString, sizeof(String),
  134.      XtOffsetOf(AppResources, save_fail), XtRImmediate, "Cannot save file: "},
  135.     {"openWindows", "OpenWindows", XtRBoolean, sizeof(Boolean),
  136.      XtOffsetOf(AppResources, openwindows), XtRImmediate, (XtPointer)False},
  137.     {"ncdwm", "Ncdwm", XtRBoolean, sizeof(Boolean),
  138.      XtOffsetOf(AppResources, ncdwm), XtRImmediate, (XtPointer)False},
  139. };
  140.  
  141. static XrmOptionDescRec options[] = {
  142.     {"-staticgray", "*Visual", XrmoptionNoArg, "StaticGray"},
  143.     {"-grayscale", "*Visual", XrmoptionNoArg, "GrayScale"},
  144.     {"-staticcolor", "*Visual", XrmoptionNoArg, "StaticColor"},
  145.     {"-pseudocolor", "*Visual", XrmoptionNoArg, "PseudoColor"},
  146.     {"-truecolor", "*Visual", XrmoptionNoArg, "TrueColor"},
  147.     {"-directcolor", "*Visual", XrmoptionNoArg, "DirectColor"},
  148.     {"-page", ".page", XrmoptionSepArg, NULL},
  149.     {"-title", ".showTitle", XrmoptionNoArg, "True"},
  150.     {"-notitle", ".showTitle", XrmoptionNoArg, "False"},
  151.     {"-date", ".showDate", XrmoptionNoArg, "True"},
  152.     {"-nodate", ".showDate", XrmoptionNoArg, "False"},
  153.     {"-locator", ".showLocator", XrmoptionNoArg, "True"},
  154.     {"-nolocator", ".showLocator", XrmoptionNoArg, "False"},
  155.     {"-center", ".autoCenter", XrmoptionNoArg, "True"},
  156.     {"-nocenter", ".autoCenter", XrmoptionNoArg, "False"},
  157.     {"-labels", ".Labels", XrmoptionNoArg, "True"},
  158.     {"-nolabels", ".Labels", XrmoptionNoArg, "False"},
  159.     {"-install", ".installStdCmap", XrmoptionNoArg, "True"},
  160.     {"-noinstall", ".installStdCmap", XrmoptionNoArg, "False"},
  161.     {"-retain", ".retainStdCmap", XrmoptionNoArg, "True"},
  162.     {"-noretain", ".retainStdCmap", XrmoptionNoArg, "False"},
  163.     {"-private", ".privateCmap", XrmoptionNoArg, "True"},
  164.     {"-noprivate", ".privateCmap", XrmoptionNoArg, "False"},
  165.     {"-quiet", "*Ghostview.quiet", XrmoptionNoArg, "True"},
  166.     {"-noquiet", "*Ghostview.quiet", XrmoptionNoArg, "False"},
  167.     {"-preload", "*Ghostview.preload", XrmoptionSepArg, NULL},
  168.     {"-xdpi", "*Ghostview.xdpi", XrmoptionSepArg, NULL},
  169.     {"-ydpi", "*Ghostview.ydpi", XrmoptionSepArg, NULL},
  170.     {"-dpi", "*Ghostview.Resolution", XrmoptionSepArg, NULL},
  171.     {"-resolution", "*Ghostview.Resolution", XrmoptionSepArg, NULL},
  172.     {"-magstep", ".magstep", XrmoptionSepArg, NULL},
  173.     {"-portrait", ".orientation", XrmoptionNoArg, "Portrait"},
  174.     {"-landscape", ".orientation", XrmoptionNoArg, "Landscape"},
  175.     {"-upsidedown", ".orientation", XrmoptionNoArg, "Upside-down"},
  176.     {"-seascape", ".orientation", XrmoptionNoArg, "Seascape"},
  177.     {"-forceorientation", ".forceOrientation", XrmoptionNoArg, "True"},
  178.     {"-letter", ".pageMedia", XrmoptionNoArg, "Letter"},
  179.     {"-tabloid", ".pageMedia", XrmoptionNoArg, "Tabloid"},
  180.     {"-ledger", ".pageMedia", XrmoptionNoArg, "Ledger"},
  181.     {"-legal", ".pageMedia", XrmoptionNoArg, "Legal"},
  182.     {"-statement", ".pageMedia", XrmoptionNoArg, "Statement"},
  183.     {"-executive", ".pageMedia", XrmoptionNoArg, "Executive"},
  184.     {"-a3", ".pageMedia", XrmoptionNoArg, "A3"},
  185.     {"-a4", ".pageMedia", XrmoptionNoArg, "A4"},
  186.     {"-a5", ".pageMedia", XrmoptionNoArg, "A5"},
  187.     {"-b4", ".pageMedia", XrmoptionNoArg, "B4"},
  188.     {"-b5", ".pageMedia", XrmoptionNoArg, "B5"},
  189.     {"-folio", ".pageMedia", XrmoptionNoArg, "Folio"},
  190.     {"-quarto", ".pageMedia", XrmoptionNoArg, "Quarto"},
  191.     {"-10x14", ".pageMedia", XrmoptionNoArg, "10x14"},
  192.     {"-forcemedia", ".forcePageMedia", XrmoptionNoArg, "True"},
  193.     {"-force", ".Force", XrmoptionNoArg, "True"},
  194.     {"-swap", ".swapLandscape", XrmoptionNoArg, "True"},
  195.     {"-noswap", ".swapLandscape", XrmoptionNoArg, "False"},
  196.     {"-openwindows", ".openWindows", XrmoptionNoArg, "True"},
  197.     {"-noopenwindows", ".openWindows", XrmoptionNoArg, "False"},
  198.     {"-ncdwm", ".ncdwm", XrmoptionNoArg, "True"},
  199.     {"-noncdwm", ".ncdwm", XrmoptionNoArg, "False"},
  200. };
  201.  
  202. static XtActionsRec actions[] = {
  203.     {"GhostviewCopyright",    gv_copyright},
  204.     {"GhostviewQuit",        gv_quit},
  205.     {"GhostviewOpen",        gv_open},
  206.     {"GhostviewReopen",        gv_reopen},
  207.     {"GhostviewSave",        gv_save},
  208.     {"GhostviewPrintWhole",    gv_print_whole},
  209.     {"GhostviewPrintMarked",    gv_print_marked},
  210.     {"GhostviewPrevious",    gv_prev},
  211.     {"GhostviewShow",        gv_show},
  212.     {"GhostviewNext",        gv_next},
  213.     {"GhostviewCenter",        gv_center},
  214.     {"GhostviewMark",        gv_mark},
  215.     {"GhostviewUnmark",        gv_unmark},
  216.     {"GhostviewSetMagstep",    gv_set_magstep},
  217.     {"GhostviewIncreaseMagstep",gv_increase_magstep},
  218.     {"GhostviewDecreaseMagstep",gv_decrease_magstep},
  219.     {"GhostviewSetOrientation",    gv_set_orientation},
  220.     {"GhostviewSwapLandscape",    gv_swap_landscape},
  221.     {"GhostviewSetPageMedia",    gv_set_pagemedia},
  222.     {"GhostviewDefault",    gv_default},
  223.     {"GhostviewForce",        gv_force},
  224.     {"GhostviewDeleteWindow",    gv_delete_window},
  225.     {"GhostviewDeleteZoom",    gv_delete_zoom},
  226.     {"GhostviewDismiss",    gv_dismiss},
  227.     {"GhostviewScrollUp",    gv_scroll_up},
  228.     {"GhostviewScrollDown",    gv_scroll_down},
  229.     {"GhostviewScrollLeft",    gv_scroll_left},
  230.     {"GhostviewScrollRight",    gv_scroll_right},
  231.     {"GhostviewEraseLocator",    gv_erase_locator},
  232.     {"GhostviewCheckFile",    gv_check_file},
  233. };
  234.  
  235. String fallback_resources[] = {
  236. #   include "app-defaults.h"
  237.     NULL
  238. };
  239.  
  240. #define ROWS 22
  241. #define COLS 68
  242. static String copyright = "\
  243. Ghostview -- An X11 user interface for ghostscript.\n\
  244. Copyright (C) 1992  Timothy O. Theisen\n\
  245. \n\
  246. This program is free software; you can redistribute it and/or modify\n\
  247. it under the terms of the GNU General Public License as published by\n\
  248. the Free Software Foundation; either version 2 of the License, or\n\
  249. (at your option) any later version.\n\
  250. \n\
  251. This program is distributed in the hope that it will be useful,\n\
  252. but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
  253. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
  254. GNU General Public License for more details.\n\
  255. \n\
  256. You should have received a copy of the GNU General Public License\n\
  257. along with this program; if not, write to the Free Software\n\
  258. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\
  259. \n\
  260.   Author: Tim Theisen           Systems Programmer\n\
  261. Internet: tim@cs.wisc.edu       Department of Computer Sciences\n\
  262.     UUCP: uwvax!tim             University of Wisconsin-Madison\n\
  263.    Phone: (608)262-0438         1210 West Dayton Street\n\
  264.      FAX: (608)262-9777         Madison, WI   53706";
  265.  
  266. static void Syntax();
  267.  
  268. float    default_xdpi;    /* default xdpi from ghostview widget */
  269. float    default_ydpi;    /* default ydpi from ghostview widget */
  270.  
  271. int    num_ghosts;    /* number of ghostview widgets active */
  272. FILE    *psfile;    /* file to display */
  273. String    filename;    /* its filename */
  274. String    oldfilename;    /* previous filename */
  275. int    current_page;    /* current page being displayed */
  276. int    current_magstep;/* current magnification */
  277. XtPageOrientation    current_orientation; /* current orientation */
  278. int    default_pagemedia;    /* index into document media or papersizes */
  279. int    current_pagemedia;    /* index into document media or papersizes */
  280. Boolean    force_document_media;    /* Whether to force a document media */
  281. int    document_media;        /* document media being forced */
  282. int    current_llx;        /* current bounding box */
  283. int    current_lly;
  284. int    current_urx;
  285. int    current_ury;
  286. int    base_papersize;        /* tells where papersizes begins */
  287. Boolean    info_up;        /* tells if information window is up */
  288. int    force_setting;        /* tells if new setting override %%comments */
  289. Pixmap    dot_bitmap;        /* bitmap used to mark default setting */
  290. Pixmap    menu16_bitmap;        /* bitmap used to mark document setting */
  291. Pixmap    tie_fighter_bitmap;    /* bitmap used to mark forced setting */
  292. String    toc_text;    /* page labels (Table of Contents) */
  293. int    toc_length;    /* length of page label text */
  294. int    toc_entry_length; /* length of one entry */
  295. int    info_length;    /* number of bytes in infotext window */
  296. int    mode;    /* tells what type of popup */
  297. time_t    mtime;        /* last modified time of input file */
  298. struct document *doc;    /* document structure */
  299. struct document *olddoc;    /* document structure */
  300. Colormap    cmap;    /* colormap being used */
  301. Boolean    special_cmap;    /* Is cmap not the Default Colormap */
  302. Pixel    white;        /* white pixel in above colormap */
  303. Pixel    black;        /* black pixel in above colormap */
  304. Atom    wm_delete_window;    /* Atom sent to destroy a window */
  305. XErrorHandler    old_Xerror;    /* standard error handler */
  306. Boolean    dying;        /* whether an X error caused our exit */
  307. XErrorEvent    bomb;    /* what the error was */
  308.  
  309. XtAppContext app_con;
  310. AppResources app_res;
  311.  
  312. /* Widgets used.  Indentation indicates hierarchy */
  313.         Widget toplevel;
  314.         Widget     form;
  315.         Widget         titlebutton;
  316.         Widget             titlemenu;
  317.         Widget         datebutton;
  318.         Widget             datemenu;
  319.         Widget         locator;
  320.         Widget         box;
  321.         Widget             filebutton;
  322.         Widget                 filemenu;
  323.         Widget                     openbutton;
  324.         Widget                     reopenbutton;
  325.         Widget                     printwholebutton;
  326.         Widget                     printmarkedbutton;
  327.         Widget                     savebutton;
  328.         Widget                     copyrightbutton;
  329.         Widget                     quitbutton;
  330.         Widget             pagebutton;
  331.         Widget                 pagemenu;
  332.         Widget                     nextbutton;
  333.         Widget                     showbutton;
  334.         Widget                     prevbutton;
  335.         Widget                     centerbutton;
  336.         Widget                     markbutton;
  337.         Widget                     unmarkbutton;
  338.         Widget             magstepbutton;
  339.         Widget                 magstepmenu;
  340.         Widget                     *magstepentry;
  341.         Widget             orientationbutton;
  342.         Widget                 orientationmenu;
  343.         Widget                     portraitbutton;
  344.         Widget                     landscapebutton;
  345.         Widget                     upsidedownbutton;
  346.         Widget                     seascapebutton;
  347.         Widget                     swapbutton;
  348.         Widget             pagemediabutton;
  349.         Widget                 pagemediamenu;
  350.         Widget                     *pagemediaentry;
  351.         Widget         toc;
  352.         Widget         pageview;
  353.         Widget             page;
  354.  
  355. /* Popup children */
  356.         Widget infopopup;
  357.         Widget     infoform;
  358.         Widget         infotext;
  359.         Widget         infodismiss;
  360.         Widget copyrightpopup;
  361.         Widget     copyrightform;
  362.         Widget         copyrighttext;
  363.         Widget         copyrightdismiss;
  364.         Widget dialogpopup;
  365.         Widget     dialog;
  366.  
  367. int
  368. main(argc, argv)
  369. int argc;
  370. char *argv[];
  371. {
  372.     struct stat sbuf;
  373.     Display *dpy;
  374.     Screen *scr;
  375.     Arg args[20];
  376.     Cardinal num_args;
  377.     Widget above_toc;
  378.     Widget left_of_page;
  379.     Widget line;
  380.     int i;
  381.     Boolean set_vert_dist;
  382.     String s1, s2;
  383.     XFontStruct *font;
  384.     XTextProperty nameprop;
  385.     Dimension bottomMargin, leftMargin, rightMargin, topMargin;
  386.     Dimension width, height;
  387.     Dimension button_width;
  388.     static String nothing = "";
  389.     static XawTextSelectType sarry[] =
  390.         {XawselectLine, XawselectAll, XawselectNull};
  391.  
  392.     XtToolkitInitialize();
  393.     XtSetTypeConverter(XtRString, XtRPageOrientation,
  394.                XmuCvtStringToPageOrientation, NULL, 0,
  395.                XtCacheAll, NULL);
  396.     app_con = XtCreateApplicationContext();
  397.     XtAppAddActions(app_con, actions, XtNumber(actions));
  398.     XtAppSetFallbackResources(app_con, fallback_resources);
  399.     dpy = XtOpenDisplay(app_con, NULL, NULL, "Ghostview",
  400.             options, XtNumber(options), &argc, argv);
  401.     if (dpy == NULL) {
  402.     fprintf(stderr, "%s: cannot open DISPLAY.\n", argv[0]);
  403.     exit(1);
  404.     }
  405.     if (argc > 2) Syntax(argv[0]);
  406.     if (argc == 2) {
  407.     filename = XtNewString(argv[1]);
  408.     if (strcmp(filename, "-")) {
  409. #ifdef VMS
  410.         if ((psfile = fopen(argv[1], "r", "mbc=100")) == NULL) {
  411. #else
  412.         if ((psfile = fopen(argv[1], "r")) == NULL) {
  413. #endif
  414.         fprintf(stderr, "Cannot open ");
  415.         perror(argv[1]);
  416.         exit(1);
  417.         }
  418.         stat(filename, &sbuf);
  419.         mtime = sbuf.st_mtime;
  420.     }
  421.     }
  422.  
  423.     old_Xerror = XSetErrorHandler(catch_Xerror);
  424.     scr = DefaultScreenOfDisplay(dpy);
  425.     wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  426.  
  427.     toplevel = XtAppCreateShell(NULL, "Ghostview", applicationShellWidgetClass,
  428.                 dpy, NULL, ZERO);
  429.  
  430.     XtGetApplicationResources(toplevel, (XtPointer) &app_res,
  431.                   resources, XtNumber(resources), NULL, ZERO);
  432.     if (s1 = getenv(app_res.printer_variable)) app_res.default_printer = s1;
  433.     SetStandardColormap(toplevel);
  434.  
  435.     /* Open Windows sometimes hands me a bad bitmap */
  436.     if (app_res.openwindows) {
  437.     dot_bitmap = menu16_bitmap = tie_fighter_bitmap = None;
  438.     } else {
  439.     dot_bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr),
  440.                        dot_bits, dot_width, dot_height);
  441.     menu16_bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr),
  442.                           menu16_bits, menu16_width,
  443.                           menu16_height);
  444.     tie_fighter_bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr),
  445.                            tie_fighter_bits,
  446.                            tie_fighter_width,
  447.                            tie_fighter_height);
  448.     }
  449.     
  450.     /* Instantiate Popup children */
  451.                             num_args = 0;
  452.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  453.     if (special_cmap) {
  454.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  455.     }
  456.     infopopup = XtCreatePopupShell("information", topLevelShellWidgetClass,
  457.                    toplevel, args, num_args);
  458.  
  459.                             num_args = 0;
  460.     if (special_cmap) {
  461.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  462.     }
  463.     infoform = XtCreateManagedWidget("form", formWidgetClass,
  464.                      infopopup, args, num_args);
  465.  
  466.                             num_args = 0;
  467.     if (special_cmap) {
  468.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  469.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  470.     }
  471.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  472.     XtSetArg(args[num_args], XtNbottom, XtChainBottom);    num_args++;
  473.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  474.     XtSetArg(args[num_args], XtNright, XtChainRight);    num_args++;
  475.     XtSetArg(args[num_args], XtNscrollHorizontal, XawtextScrollWhenNeeded);
  476.                             num_args++;
  477.     XtSetArg(args[num_args], XtNscrollVertical, XawtextScrollWhenNeeded);
  478.                             num_args++;
  479.     XtSetArg(args[num_args], XtNdisplayCaret, False);    num_args++;
  480.     infotext = XtCreateManagedWidget("text", asciiTextWidgetClass,
  481.                      infoform, args, num_args);
  482.  
  483.                             num_args = 0;
  484.     if (special_cmap) {
  485.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  486.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  487.     }
  488.     XtSetArg(args[num_args], XtNfromVert, infotext);    num_args++;
  489.     XtSetArg(args[num_args], XtNtop, XtChainBottom);    num_args++;
  490.     XtSetArg(args[num_args], XtNbottom, XtChainBottom);    num_args++;
  491.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  492.     XtSetArg(args[num_args], XtNright, XtChainRight);    num_args++;
  493.     infodismiss = XtCreateManagedWidget("dismiss", commandWidgetClass,
  494.                        infoform, args, num_args);
  495.     XtAddCallback(infodismiss, XtNcallback, dismiss, (XtPointer)infopopup);
  496.  
  497.                             num_args = 0;
  498.     XtSetArg(args[num_args], XtNfont, &font);        num_args++;
  499.     XtSetArg(args[num_args], XtNbottomMargin, &bottomMargin);num_args++;
  500.     XtSetArg(args[num_args], XtNleftMargin, &leftMargin);num_args++;
  501.     XtSetArg(args[num_args], XtNrightMargin, &rightMargin);num_args++;
  502.     XtSetArg(args[num_args], XtNtopMargin, &topMargin);    num_args++;
  503.     XtGetValues(infotext, args, num_args);
  504.  
  505.     width = font->max_bounds.width * 80 + leftMargin + rightMargin;
  506.     height = (font->ascent + font->descent) * ROWS + topMargin + bottomMargin;
  507.  
  508.     XtSetArg(args[0], XtNwidth, width);
  509.     XtSetArg(args[1], XtNheight, height);
  510.     XtSetValues(infotext, args, TWO);
  511.     XtSetValues(infodismiss, args, ONE);
  512.     XtRealizeWidget(infopopup);
  513.     XSetWMProtocols(dpy, XtWindow(infopopup), &wm_delete_window, 1);
  514.  
  515.                             num_args = 0;
  516.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  517.     if (special_cmap) {
  518.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  519.     }
  520.     copyrightpopup = XtCreatePopupShell("copyright", topLevelShellWidgetClass,
  521.                     toplevel, args, num_args);
  522.  
  523.                             num_args = 0;
  524.     if (special_cmap) {
  525.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  526.     }
  527.     copyrightform = XtCreateManagedWidget("form", formWidgetClass,
  528.                       copyrightpopup, args, num_args);
  529.  
  530.                             num_args = 0;
  531.     if (special_cmap) {
  532.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  533.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  534.     }
  535.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  536.     XtSetArg(args[num_args], XtNbottom, XtChainBottom);    num_args++;
  537.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  538.     XtSetArg(args[num_args], XtNright, XtChainRight);    num_args++;
  539.     XtSetArg(args[num_args], XtNscrollHorizontal, XawtextScrollWhenNeeded);
  540.                             num_args++;
  541.     XtSetArg(args[num_args], XtNscrollVertical, XawtextScrollWhenNeeded);
  542.                             num_args++;
  543.     XtSetArg(args[num_args], XtNdisplayCaret, False);    num_args++;
  544.     XtSetArg(args[num_args], XtNuseStringInPlace, True);num_args++;
  545.     XtSetArg(args[num_args], XtNlength, strlen(copyright));num_args++;
  546.     XtSetArg(args[num_args], XtNstring, copyright);    num_args++;
  547.     copyrighttext = XtCreateManagedWidget("text", asciiTextWidgetClass,
  548.                       copyrightform, args, num_args);
  549.  
  550.                             num_args = 0;
  551.     if (special_cmap) {
  552.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  553.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  554.     }
  555.     XtSetArg(args[num_args], XtNfromVert, copyrighttext);
  556.                             num_args++;
  557.     XtSetArg(args[num_args], XtNtop, XtChainBottom);    num_args++;
  558.     XtSetArg(args[num_args], XtNbottom, XtChainBottom);    num_args++;
  559.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  560.     XtSetArg(args[num_args], XtNright, XtChainRight);    num_args++;
  561.     copyrightdismiss = XtCreateManagedWidget("dismiss", commandWidgetClass,
  562.                          copyrightform, args, num_args);
  563.     XtAddCallback(copyrightdismiss, XtNcallback, dismiss,
  564.           (XtPointer)copyrightpopup);
  565.  
  566.                             num_args = 0;
  567.     XtSetArg(args[num_args], XtNfont, &font);        num_args++;
  568.     XtSetArg(args[num_args], XtNbottomMargin, &bottomMargin);num_args++;
  569.     XtSetArg(args[num_args], XtNleftMargin, &leftMargin);num_args++;
  570.     XtSetArg(args[num_args], XtNrightMargin, &rightMargin);num_args++;
  571.     XtSetArg(args[num_args], XtNtopMargin, &topMargin);    num_args++;
  572.     XtGetValues(copyrighttext, args, num_args);
  573.  
  574.     width = font->max_bounds.width * COLS + leftMargin + rightMargin;
  575.     height = (font->ascent + font->descent) * ROWS + topMargin + bottomMargin;
  576.  
  577.     XtSetArg(args[0], XtNwidth, width);
  578.     XtSetArg(args[1], XtNheight, height);
  579.     XtSetValues(copyrighttext, args, TWO);
  580.     XtSetValues(copyrightdismiss, args, ONE);
  581.     XtRealizeWidget(copyrightpopup);
  582.     XSetWMProtocols(dpy, XtWindow(copyrightpopup), &wm_delete_window, 1);
  583.  
  584.                             num_args = 0;
  585.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  586.     if (special_cmap) {
  587.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  588.     }
  589.     dialogpopup = XtCreatePopupShell("popup", transientShellWidgetClass,
  590.                      toplevel, args, num_args);
  591.  
  592.     dialog = CreateDialog(dialogpopup, "dialog", okay, dismiss);
  593.     XtRealizeWidget(dialogpopup);
  594.     XSetWMProtocols(dpy, XtWindow(dialogpopup), &wm_delete_window, 1);
  595.  
  596.  
  597.     /* Instantiate Widgets */
  598.  
  599.                             num_args = 0;
  600.     if (special_cmap) {
  601.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  602.     }
  603.     form = XtCreateManagedWidget("form", formWidgetClass,
  604.                  toplevel, args, num_args);
  605.  
  606.     above_toc = NULL;
  607.     left_of_page = NULL;
  608.     set_vert_dist = False;
  609.     if (app_res.show_title) {
  610.                             num_args = 0;
  611.     if (special_cmap) {
  612.         XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  613.         XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  614.     }
  615.     XtSetArg(args[num_args], XtNfromVert, above_toc);num_args++;
  616.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  617.     XtSetArg(args[num_args], XtNbottom, XtChainTop);num_args++;
  618.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  619.     XtSetArg(args[num_args], XtNright, XtChainLeft);num_args++;
  620.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  621.     XtSetArg(args[num_args], XtNborderWidth, 0);    num_args++;
  622.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  623.     XtSetArg(args[num_args], XtNlabel, " ");    num_args++;
  624.     titlebutton = XtCreateManagedWidget("titleButton",
  625.                         menuButtonWidgetClass,
  626.                             form, args, num_args);
  627.     above_toc = titlebutton;
  628.     if (!left_of_page) left_of_page = titlebutton;
  629.     set_vert_dist = True;
  630.     }
  631.  
  632.     if (app_res.show_date) {
  633.                             num_args = 0;
  634.     if (special_cmap) {
  635.         XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  636.         XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  637.     }
  638.     XtSetArg(args[num_args], XtNfromVert, above_toc);num_args++;
  639.     if (set_vert_dist) {
  640.         XtSetArg(args[num_args], XtNvertDistance, 0);num_args++;
  641.     }
  642.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  643.     XtSetArg(args[num_args], XtNbottom, XtChainTop);num_args++;
  644.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  645.     XtSetArg(args[num_args], XtNright, XtChainLeft);num_args++;
  646.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  647.     XtSetArg(args[num_args], XtNborderWidth, 0);    num_args++;
  648.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  649.     XtSetArg(args[num_args], XtNlabel, " ");    num_args++;
  650.     datebutton = XtCreateManagedWidget("dateButton", menuButtonWidgetClass,
  651.                        form, args, num_args);
  652.     above_toc = datebutton;
  653.     if (!left_of_page) left_of_page = datebutton;
  654.     set_vert_dist = True;
  655.     }
  656.  
  657.     if (app_res.show_locator) {
  658.                             num_args = 0;
  659.     if (special_cmap) {
  660.         XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  661.         XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  662.     }
  663.     XtSetArg(args[num_args], XtNfromVert, above_toc);num_args++;
  664.     if (set_vert_dist) {
  665.         XtSetArg(args[num_args], XtNvertDistance, 0);num_args++;
  666.     }
  667.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  668.     XtSetArg(args[num_args], XtNbottom, XtChainTop);num_args++;
  669.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  670.     XtSetArg(args[num_args], XtNright, XtChainLeft);num_args++;
  671.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  672.     XtSetArg(args[num_args], XtNborderWidth, 0);    num_args++;
  673.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  674.     XtSetArg(args[num_args], XtNlabel, " ");    num_args++;
  675.     locator = XtCreateManagedWidget("locator", labelWidgetClass,
  676.                     form, args, num_args);
  677.     above_toc = locator;
  678.     if (!left_of_page) left_of_page = locator;
  679.     }
  680.  
  681.                             num_args = 0;
  682.     if (special_cmap) {
  683.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  684.     }
  685.     XtSetArg(args[num_args], XtNfromVert, above_toc);    num_args++;
  686.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  687.     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  688.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  689.     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  690.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  691.     XtSetArg(args[num_args], XtNallowVert, True);    num_args++;
  692.     box = XtCreateManagedWidget("box", boxWidgetClass, form, args, num_args);
  693.  
  694.                             num_args = 0;
  695.     if (special_cmap) {
  696.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  697.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  698.     }
  699.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  700.     filebutton = XtCreateManagedWidget("fileButton", menuButtonWidgetClass,
  701.                        box, args, num_args);
  702.  
  703.                             num_args = 0;
  704.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  705.     if (special_cmap) {
  706.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  707.     }
  708.     filemenu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
  709.                   filebutton, args, num_args);
  710.  
  711.                             num_args = 0;
  712.     if (special_cmap) {
  713.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  714.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  715.     }
  716.     openbutton = XtCreateManagedWidget("open", smeBSBObjectClass,
  717.                        filemenu, args, num_args);
  718.     XtAddCallback(openbutton, XtNcallback, popup_dialog, (XtPointer)OPEN);
  719.  
  720.                             num_args = 0;
  721.     if (special_cmap) {
  722.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  723.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  724.     }
  725.     reopenbutton = XtCreateManagedWidget("reopen", smeBSBObjectClass,
  726.                          filemenu, args, num_args);
  727.     XtAddCallback(reopenbutton, XtNcallback, reopen_file, (XtPointer)NULL);
  728.  
  729.                             num_args = 0;
  730.     if (special_cmap) {
  731.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  732.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  733.     }
  734.     printwholebutton = XtCreateManagedWidget("printwhole", smeBSBObjectClass,
  735.                              filemenu, args, num_args);
  736.     XtAddCallback(printwholebutton, XtNcallback, popup_dialog,
  737.           (XtPointer)PRINT_WHOLE);
  738.  
  739.                             num_args = 0;
  740.     if (special_cmap) {
  741.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  742.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  743.     }
  744.     printmarkedbutton = XtCreateManagedWidget("printmarked", smeBSBObjectClass,
  745.                               filemenu, args, num_args);
  746.     XtAddCallback(printmarkedbutton, XtNcallback, popup_dialog,
  747.           (XtPointer)PRINT_MARKED);
  748.  
  749.                             num_args = 0;
  750.     if (special_cmap) {
  751.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  752.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  753.     }
  754.     savebutton = XtCreateManagedWidget("save", smeBSBObjectClass,
  755.                        filemenu, args, num_args);
  756.     XtAddCallback(savebutton, XtNcallback, popup_dialog, (XtPointer)SAVE);
  757.  
  758.                             num_args = 0;
  759.     if (special_cmap) {
  760.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  761.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  762.     }
  763.     line = XtCreateManagedWidget("line", smeLineObjectClass,
  764.                  filemenu, args, num_args);
  765.  
  766.                             num_args = 0;
  767.     if (special_cmap) {
  768.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  769.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  770.     }
  771.     copyrightbutton = XtCreateManagedWidget("copyright", smeBSBObjectClass,
  772.                         filemenu, args, num_args);
  773.     XtAddCallback(copyrightbutton, XtNcallback, popup,
  774.           (XtPointer)copyrightpopup);
  775.  
  776.                             num_args = 0;
  777.     if (special_cmap) {
  778.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  779.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  780.     }
  781.     quitbutton = XtCreateManagedWidget("quit", smeBSBObjectClass,
  782.                        filemenu, args, num_args);
  783.     XtAddCallback(quitbutton, XtNcallback, quit_ghostview, (XtPointer)0);
  784.  
  785.                             num_args = 0;
  786.     if (special_cmap) {
  787.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  788.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  789.     }
  790.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  791.     pagebutton = XtCreateManagedWidget("pageButton", menuButtonWidgetClass,
  792.                        box, args, num_args);
  793.  
  794.                             num_args = 0;
  795.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  796.     if (special_cmap) {
  797.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  798.     }
  799.     pagemenu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
  800.                   pagebutton, args, num_args);
  801.  
  802.                             num_args = 0;
  803.     if (special_cmap) {
  804.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  805.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  806.     }
  807.     nextbutton = XtCreateManagedWidget("next", smeBSBObjectClass,
  808.                        pagemenu, args, num_args);
  809.     XtAddCallback(nextbutton, XtNcallback, next_page, (XtPointer)0);
  810.  
  811.                             num_args = 0;
  812.     if (special_cmap) {
  813.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  814.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  815.     }
  816.     showbutton = XtCreateManagedWidget("show", smeBSBObjectClass,
  817.                        pagemenu, args, num_args);
  818.     XtAddCallback(showbutton, XtNcallback, this_page, (XtPointer)0);
  819.  
  820.                             num_args = 0;
  821.     if (special_cmap) {
  822.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  823.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  824.     }
  825.     prevbutton = XtCreateManagedWidget("prev", smeBSBObjectClass,
  826.                        pagemenu, args, num_args);
  827.     XtAddCallback(prevbutton, XtNcallback, prev_page, (XtPointer)0);
  828.  
  829.                             num_args = 0;
  830.     if (special_cmap) {
  831.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  832.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  833.     }
  834.     line = XtCreateManagedWidget("line", smeLineObjectClass,
  835.                  pagemenu, args, num_args);
  836.  
  837.                             num_args = 0;
  838.     if (special_cmap) {
  839.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  840.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  841.     }
  842.     centerbutton = XtCreateManagedWidget("center", smeBSBObjectClass,
  843.                        pagemenu, args, num_args);
  844.     XtAddCallback(centerbutton, XtNcallback, center_page, (XtPointer)0);
  845.  
  846.                             num_args = 0;
  847.     if (special_cmap) {
  848.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  849.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  850.     }
  851.     line = XtCreateManagedWidget("line", smeLineObjectClass,
  852.                  pagemenu, args, num_args);
  853.  
  854.                             num_args = 0;
  855.     if (special_cmap) {
  856.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  857.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  858.     }
  859.     markbutton = XtCreateManagedWidget("mark", smeBSBObjectClass,
  860.                        pagemenu, args, num_args);
  861.     XtAddCallback(markbutton, XtNcallback, mark_page, (XtPointer)0);
  862.  
  863.                             num_args = 0;
  864.     if (special_cmap) {
  865.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  866.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  867.     }
  868.     unmarkbutton = XtCreateManagedWidget("unmark", smeBSBObjectClass,
  869.                          pagemenu, args, num_args);
  870.     XtAddCallback(unmarkbutton, XtNcallback, unmark_page, (XtPointer)0);
  871.  
  872.                             num_args = 0;
  873.     if (special_cmap) {
  874.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  875.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  876.     }
  877.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  878.     magstepbutton = XtCreateManagedWidget("magstepButton",
  879.                       menuButtonWidgetClass,
  880.                       box, args, num_args);
  881.  
  882.                             num_args = 0;
  883.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  884.     if (special_cmap) {
  885.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  886.     }
  887.     magstepmenu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
  888.                      magstepbutton, args, num_args);
  889.  
  890.     magstepentry = (Widget *) XtMalloc(
  891.         (app_res.maximum_magstep - app_res.minimum_magstep + 1) *
  892.         sizeof(Widget));
  893.     for (i = app_res.minimum_magstep; i <= app_res.maximum_magstep; i++) {
  894.     char buf[16];
  895.     sprintf(buf, "%d", i);
  896.                             num_args = 0;
  897.     if (special_cmap) {
  898.         XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  899.         XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  900.     }
  901.     XtSetArg(args[num_args], XtNleftMargin, 20);    num_args++;
  902.     magstepentry[i-app_res.minimum_magstep] =
  903.         XtCreateManagedWidget(buf, smeBSBObjectClass,
  904.                       magstepmenu, args, num_args);
  905.     XtAddCallback(magstepentry[i-app_res.minimum_magstep], XtNcallback,
  906.               set_magstep, (XtPointer)i);
  907.     }
  908.  
  909.                             num_args = 0;
  910.     if (special_cmap) {
  911.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  912.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  913.     }
  914.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  915.     orientationbutton = XtCreateManagedWidget("orientationButton",
  916.                           menuButtonWidgetClass,
  917.                           box, args, num_args);
  918.  
  919.                             num_args = 0;
  920.     XtSetArg(args[num_args], XtNcolormap, cmap);    num_args++;
  921.     if (special_cmap) {
  922.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  923.     }
  924.     orientationmenu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
  925.                          orientationbutton, args, num_args);
  926.  
  927.                             num_args = 0;
  928.     if (special_cmap) {
  929.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  930.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  931.     }
  932.     XtSetArg(args[num_args], XtNleftMargin, 20);    num_args++;
  933.     portraitbutton = XtCreateManagedWidget("portrait", smeBSBObjectClass,
  934.                            orientationmenu, args, num_args);
  935.     XtAddCallback(portraitbutton, XtNcallback,
  936.           set_orientation, (XtPointer)XtPageOrientationPortrait);
  937.  
  938.                             num_args = 0;
  939.     if (special_cmap) {
  940.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  941.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  942.     }
  943.     XtSetArg(args[num_args], XtNleftMargin, 20);    num_args++;
  944.     landscapebutton = XtCreateManagedWidget("landscape", smeBSBObjectClass,
  945.                             orientationmenu, args, num_args);
  946.     XtAddCallback(landscapebutton, XtNcallback,
  947.           set_orientation, (XtPointer)XtPageOrientationLandscape);
  948.  
  949.                             num_args = 0;
  950.     if (special_cmap) {
  951.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  952.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  953.     }
  954.     XtSetArg(args[num_args], XtNleftMargin, 20);    num_args++;
  955.     upsidedownbutton = XtCreateManagedWidget("upsidedown", smeBSBObjectClass,
  956.                              orientationmenu, args, num_args);
  957.     XtAddCallback(upsidedownbutton, XtNcallback,
  958.           set_orientation, (XtPointer)XtPageOrientationUpsideDown);
  959.  
  960.                             num_args = 0;
  961.     if (special_cmap) {
  962.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  963.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  964.     }
  965.     XtSetArg(args[num_args], XtNleftMargin, 20);    num_args++;
  966.     seascapebutton = XtCreateManagedWidget("seascape", smeBSBObjectClass,
  967.                              orientationmenu, args, num_args);
  968.     XtAddCallback(seascapebutton, XtNcallback,
  969.           set_orientation, (XtPointer)XtPageOrientationSeascape);
  970.  
  971.                             num_args = 0;
  972.     if (special_cmap) {
  973.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  974.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  975.     }
  976.     line = XtCreateManagedWidget("line", smeLineObjectClass,
  977.                  orientationmenu, args, num_args);
  978.  
  979.                             num_args = 0;
  980.     if (special_cmap) {
  981.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  982.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  983.     }
  984.     XtSetArg(args[num_args], XtNleftMargin, 20);    num_args++;
  985.     swapbutton = XtCreateManagedWidget("swap", smeBSBObjectClass,
  986.                        orientationmenu, args, num_args);
  987.     XtAddCallback(swapbutton, XtNcallback, swap_landscape, (XtPointer)0);
  988.  
  989.     if (app_res.swap_landscape) {
  990.     XtSetArg(args[0], XtNlabel, &s1);
  991.     XtGetValues(landscapebutton, args, ONE);
  992.     s1 = XtNewString(s1);
  993.     XtSetArg(args[0], XtNlabel, &s2);
  994.     XtGetValues(seascapebutton, args, ONE);
  995.     s2 = XtNewString(s2);
  996.     XtSetArg(args[0], XtNlabel, s2);
  997.     XtSetValues(landscapebutton, args, ONE);
  998.     XtSetArg(args[0], XtNlabel, s1);
  999.     XtSetValues(seascapebutton, args, ONE);
  1000.     XtFree(s1);
  1001.     XtFree(s2);
  1002.     }
  1003.  
  1004.                             num_args = 0;
  1005.     if (special_cmap) {
  1006.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  1007.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  1008.     }
  1009.     XtSetArg(args[num_args], XtNresize, False);    num_args++;
  1010.     pagemediabutton = XtCreateManagedWidget("pagemediaButton",
  1011.                         menuButtonWidgetClass,
  1012.                         box, args, num_args);
  1013.  
  1014.     default_pagemedia = 0;
  1015.     for (i = 0; papersizes[i].name; i++) {
  1016.         if (!strcmp(app_res.pagemedia, papersizes[i].name)) {
  1017.         default_pagemedia = i;
  1018.             break;
  1019.         }
  1020.     }
  1021.  
  1022. #ifndef max
  1023. #define max(a,b) ((a)>(b)?(a):(b))
  1024. #endif
  1025.  
  1026.     /* Line up all the menu buttons */
  1027.     XtSetArg(args[0], XtNwidth, &width);
  1028.     XtGetValues(filebutton, args, ONE);
  1029.     button_width = width;
  1030.     XtGetValues(pagebutton, args, ONE);
  1031.     button_width = max(button_width, width);
  1032.     XtGetValues(magstepbutton, args, ONE);
  1033.     button_width = max(button_width, width);
  1034.     XtGetValues(orientationbutton, args, ONE);
  1035.     button_width = max(button_width, width);
  1036.     XtGetValues(pagemediabutton, args, ONE);
  1037.     button_width = max(button_width, width);
  1038.  
  1039.     XtSetArg(args[0], XtNwidth, button_width);
  1040.     XtSetValues(filebutton, args, ONE);
  1041.     XtSetValues(pagebutton, args, ONE);
  1042.     XtSetValues(magstepbutton, args, ONE);
  1043.     XtSetValues(orientationbutton, args, ONE);
  1044.     XtSetValues(pagemediabutton, args, ONE);
  1045.  
  1046.                             num_args = 0;
  1047.     if (special_cmap) {
  1048.     XtSetArg(args[num_args], XtNforeground, black);    num_args++;
  1049.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  1050.     }
  1051.     XtSetArg(args[num_args], XtNfromVert, above_toc);    num_args++;
  1052.     XtSetArg(args[num_args], XtNfromHoriz, box);    num_args++;
  1053.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  1054.     XtSetArg(args[num_args], XtNbottom, XtChainBottom);    num_args++;
  1055.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  1056.     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  1057.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  1058.     XtSetArg(args[num_args], XtNdisplayCaret, False);    num_args++;
  1059.     XtSetArg(args[num_args], XtNuseStringInPlace, True);num_args++;
  1060.     XtSetArg(args[num_args], XtNlength, 0);        num_args++;
  1061.     XtSetArg(args[num_args], XtNstring, nothing);    num_args++;
  1062.     XtSetArg(args[num_args], XtNselectTypes, sarry);    num_args++;
  1063.     XtSetArg(args[num_args], XtNscrollVertical, XawtextScrollAlways);num_args++;
  1064.     toc = XtCreateManagedWidget("toc", asciiTextWidgetClass,
  1065.                 form, args, num_args);
  1066.     if (!left_of_page) left_of_page = toc;
  1067.  
  1068.                             num_args = 0;
  1069.     if (special_cmap) {
  1070.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  1071.     }
  1072.     XtSetArg(args[num_args], XtNfromHoriz, left_of_page);num_args++;
  1073.     XtSetArg(args[num_args], XtNtop, XtChainTop);    num_args++;
  1074.     XtSetArg(args[num_args], XtNbottom, XtChainBottom);    num_args++;
  1075.     XtSetArg(args[num_args], XtNleft, XtChainLeft);    num_args++;
  1076.     XtSetArg(args[num_args], XtNright, XtChainRight);    num_args++;
  1077.     XtSetArg(args[num_args], XtNresizable, True);    num_args++;
  1078.     XtSetArg(args[num_args], XtNallowHoriz, True);    num_args++;
  1079.     XtSetArg(args[num_args], XtNallowVert, True);    num_args++;
  1080.     pageview = XtCreateManagedWidget("pageview", viewportWidgetClass,
  1081.                      form, args, num_args);
  1082.  
  1083.                             num_args = 0;
  1084.     XtSetArg(args[num_args], XtNbackground, white);    num_args++;
  1085.     page = XtCreateManagedWidget("page", ghostviewWidgetClass,
  1086.                  pageview, args, num_args);
  1087.     num_ghosts++;
  1088.     XtAddCallback(page, XtNcallback, track_and_zoom, (XtPointer)0);
  1089.     XtAddCallback(page, XtNdestroyCallback, destroy_ghost, (XtPointer)page);
  1090.     XtAddCallback(page, XtNmessageCallback, message, (XtPointer)page);
  1091.     XtAddCallback(page, XtNoutputCallback, output, (XtPointer)0);
  1092.                             num_args = 0;
  1093.     XtSetArg(args[num_args], XtNxdpi, &default_xdpi);    num_args++;
  1094.     XtSetArg(args[num_args], XtNydpi, &default_ydpi);    num_args++;
  1095.     XtGetValues(page, args, num_args);
  1096.  
  1097.     /* This sets most of the window sizes.  This keeps X server traffic
  1098.      * down during realization.
  1099.      */
  1100.     GhostviewDisableInterpreter(page);
  1101.     setup_ghostview();
  1102.     i = find_page(app_res.page);
  1103.  
  1104.     /* Coerce page number to fall in range */
  1105.     if (toc_text) {
  1106.     if (i >= doc->numpages) i = doc->numpages - 1;
  1107.     if (i < 0) i = 0;
  1108.     }
  1109.     /* Coerce magstep to fall in range */
  1110.     if (app_res.magstep < app_res.minimum_magstep)
  1111.     app_res.magstep = app_res.minimum_magstep;
  1112.     if (app_res.magstep > app_res.maximum_magstep)
  1113.     app_res.magstep = app_res.maximum_magstep;
  1114.     set_new_magstep();
  1115.     set_new_orientation(i);
  1116.     set_new_pagemedia(i);
  1117.     layout_ghostview();
  1118.  
  1119.     XtSetMappedWhenManaged(toplevel, False);
  1120.     XtRealizeWidget(toplevel);
  1121.     XtSetArg(args[0], XtNtransientFor, toplevel);
  1122.     XtSetValues(dialogpopup, args, ONE);
  1123.     XSetWMProtocols(dpy, XtWindow(toplevel), &wm_delete_window, 1);
  1124.     if (XStringListToTextProperty(&version, 1, &nameprop)) {
  1125.     XSetWMName(dpy, XtWindow(toplevel), &nameprop);
  1126.     }
  1127.  
  1128.     /* This sets the sizes on widget that were created during the realize. */
  1129.     layout_ghostview();
  1130.     XtMapWidget(toplevel);
  1131.  
  1132.     show_page(i);
  1133.     XtAppMainLoop(app_con);
  1134.  
  1135.     /* should never get here */
  1136.     return 1;
  1137. }
  1138.  
  1139. static void
  1140. Syntax(call)
  1141. char *call;
  1142. {
  1143.     XtDestroyApplicationContext(app_con);
  1144.     fprintf(stderr, "Usage: %s\n", call);
  1145.     fprintf(stderr,
  1146.         "    [-staticgray] [-grayscale] [-staticcolor]\n");
  1147.     fprintf(stderr,
  1148.         "    [-pseudocolor] [-truecolor] [-directcolor]\n");
  1149.     fprintf(stderr,
  1150.         "    [-[no]install] [-[no]private] [-[no]center]\n");
  1151.     fprintf(stderr,
  1152.         "    [-[no]title] [-[no]date] [-[no]locator] [-[no]labels]\n");
  1153.     fprintf(stderr,
  1154.         "    [-resolution <dpi>] [-dpi <dpi>]\n");
  1155.     fprintf(stderr,
  1156.         "    [-xdpi <dpi>] [-ydpi <dpi>]\n");
  1157.     fprintf(stderr,
  1158.         "    [-[no]quiet] [-preload <file>] [-magstep <n>]\n");
  1159.     fprintf(stderr,
  1160.         "    [-portrait] [-landscape] [-upsidedown] [-seascape]\n");
  1161.     fprintf(stderr,
  1162.         "    [-letter] [-tabloid] [-ledger] [-legal] [-statement]\n");
  1163.     fprintf(stderr,
  1164.         "    [-executive] [-a3] [-a4] [-a5] [-b4] [-b5]\n");
  1165.     fprintf(stderr,
  1166.         "    [-folio] [-quarto] [-10x14]\n");
  1167.     fprintf(stderr,
  1168.         "    [-force] [-forceorientation] [-forcemedia]\n");
  1169.     fprintf(stderr,
  1170.         "    [-[no]swap] [-[no]openwindows] [-[no]ncdwm]\n");
  1171.     fprintf(stderr,
  1172.         "    [-page <label>] [toolkitoption]\n");
  1173.     fprintf(stderr,
  1174.         "    [filename]\n");
  1175.     exit(1);
  1176. }
  1177.